package require wt::core

namespace eval ::wt::samples:: {
  variable docTitle
  variable pageTitle
  variable dirLevel 0
  variable pkgDir
}

proc ::wt::samples::setTitle {pageTitleString {docTitleString {}}} {
  variable docTitle
  variable pageTitle

  if {$docTitleString == ""} {
    set docTitleString $pageTitleString
  }
  set docTitle $docTitleString

  set pageTitle $pageTitleString
}

proc ::wt::samples::appUrl {{path {}} {params {}}} {
  set url ""
  variable dirLevel
  append url [string repeat ../ $dirLevel]
  append url $path
  set url [::wt::web::relativeUrl $url $params]
  return $url
}

proc ::wt::samples::viewSourceUrl {{path {}} {params {}}} {
  variable dirLevel
  if {$path == ""} {
    set base [file normalize [::wt::server::serverVars get SCRIPT_FILENAME]]
    for {set i 0} {$i <= $dirLevel} {incr i} {
      set path [file join [file tail $base] $path]
      set base [file dirname $base]
    }
  }
  lappend params path $path
  return [appUrl viewSource.wtcl $params]
}

proc ::wt::samples::viewSourceLinkText {{fileName {}}} {
  if {$fileName == ""} {
    set fileName [::wt::web::pathBasename \
      [file normalize [::wt::server::serverVars get SCRIPT_FILENAME]]]
  }
  return "View Source for $fileName"
}

proc ::wt::samples::literal {text} {
  return "<span class=\"literal\">$text</span>"
}

package provide wt::samples 1
